//俱乐部联盟

import supMount from "../../sup/supMount"
import wnetModule from "../../glo/wnetModule"
import explorer from "../../api/ts/api_explorer";
import enumMode from "../../em/enumMode"
import gamesModule from "./gamesModule"
import clubMainModule from "./clubMainModule"

const { ccclass, property } = cc._decorator;
@ccclass
export default class cClubMainMount extends supMount {
    private msgModule: wnetModule = this.getModule(enumMode.mesgeModule)

    @property(cc.Sprite)
    private sliceds: cc.Sprite[] = [];   //九宫格
    @property(cc.Label)
    private txClub: cc.Label = null; //俱乐部
    @property(cc.Label)
    private txNotiec: cc.Label = null; //公告
    @property(cc.Label)
    private txCombat: cc.Label = null; //对局
    @property(cc.Label)
    private txMember: cc.Label = null; //成员

    //组件脚本启动扩展
    protected extendStart() {
        //获取模块
        let mod: clubMainModule = this.getModule(null)
        //获取数据
        let inf: s2c_clubClub = mod.getClubData()
        //联盟名称
        this.txClub.string = inf.club.clubName
        //个性签名
        this.txNotiec.string = inf.club.personality
        //游戏对局
        this.txCombat.string = `${inf.club.combatNumber}个牌局进行中`
        //俱乐部人数
        this.txMember.string = inf.club.memberNumber.toString()
        //加载图片
        let index: number = 0
        inf.club.logoGs.forEach(url => {
            explorer.pngRemote(url, (error: Error, image: cc.Texture2D) => {
                if (!error) {
                    this.sliceds[index++].spriteFrame = new cc.SpriteFrame(image)
                }
            })
        })
    }

    public onclube(): void {
        let mod: gamesModule = this.getModule(enumMode.gamesModule)
        if (!mod) {
            mod = new gamesModule()
        }

        let get: clubMainModule = this.getModule(null)
        let inf: s2c_clubClub = get.getClubData()
        mod.setClubID(inf.club.clubID)
        mod.changeStart()
    }
}
